﻿create PROCEDURE Sync.SP_LoanCancellingDebtAttachments_SelectChanges
@LastRowVersion rowversion,
@FilterdColumn UNIQUEIDENTIFIER
AS 
BEGIN 
	SELECT 
        t.[LoanCancellingDebtAttachmentID],
		g.[LoanCancellingDebtID],g.[Attachment],
		t.IsDeleted,
		t.LastUpdatedDate
	FROM [dbo].[LoanCancellingDebtAttachments] g RIGHT JOIN Sync.LoanCancellingDebtAttachments_Tracking t  
    ON t.LoanCancellingDebtAttachmentID = g.LoanCancellingDebtAttachmentID 
    join LoanCancellingDebts lcd on lcd.LoanCancellingDebtID = g.LoanCancellingDebtID
join CustomerLoans cl
on lcd.LoanID = cl.LoanID
	WHERE (@LastRowVersion IS NULL OR t.Version > @LastRowVersion)
	AND ((@FilterdColumn IS NULL) OR (cl.CommitteeID = @FilterdColumn))
    END











